/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package provider.impl.coalescent.lc;

import coalescent.data.KC64Data;
import coalescent.model.KC64;
import coalescent.provider.Providers;
import coalescent.recursion.ProbComputer_Exact;
import coalescent.recursion.Recursion;
import coalescent.statistic.KC64_AC;
import commons.core.LikelihoodComputer;
import commons.provider.ProviderException;
import commons.provider.impl.BaseProviderImpl;

import java.math.BigDecimal;

/**
 * @since
 * @version
 * @author Susanta Tewari
 * @history Created on 2/20/13.
 */
public class KC64ExactLCProviderImpl extends BaseProviderImpl<LikelihoodComputer<KC64Data.DEFAULT>>
        implements Providers.KC64LHoodProvider {

    @Override
    public Class<KC64Data.DEFAULT> getDataClass() {
        return KC64Data.DEFAULT.class;
    }

    @Override
    public Class<KC64> getModelClass() {
        return KC64.class;
    }

    @Override
    public LikelihoodComputer<KC64Data.DEFAULT> create() throws ProviderException {

        return new LikelihoodComputer<KC64Data.DEFAULT>() {

            @Override
            public BigDecimal computeLogLHood(final KC64Data.DEFAULT kc64Data)
                    throws InterruptedException {

                final Recursion recursion             = new Recursion(new KC64_AC(kc64Data));
                final ProbComputer_Exact probComputer = new ProbComputer_Exact();

                recursion.addExactRecursionEventListener(probComputer);
                recursion.runRecursion();

                return probComputer.getResult();
            }
        };
    }
}
